﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;

public partial class CustomerManage_IdentityManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200500107");
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());           
           
            //Bind();
        }
    }

    #region 绑定
    private void Bind()
    {
        StringBuilder Sb = new StringBuilder();
        if (txtCustomerId.Text.Length > 1) //会员账号
        {
            Sb.Append(" and CI_CustomerCode like '%");
            Sb.Append(txtCustomerId.Text.Trim());
            Sb.Append("%'");
        }
        if (txtCreateDateStart.Text.Length > 1)//认证起始时间
        {
            Sb.Append(" and CI_AddTime>'");
            Sb.Append(txtCreateDateStart.Text.Trim());
            Sb.Append("'");
        }
        if (txtCreateDateEnd.Text.Length > 1)
        {
            Sb.Append(" and CI_AddTime<'");
            Sb.Append(DateTime.Parse(txtCreateDateEnd.Text.Trim()).AddDays(1).ToShortDateString());
            Sb.Append("'");
        }
        if (dropAudit.SelectedIndex > 0)
        {
            Sb.Append(" and CI_Valid=");
            Sb.Append(dropAudit.SelectedValue);        

        }
        if (txtCheckDateStart.Text.Trim().Length > 1)
        {
            Sb.Append(" and CI_ValidTime>'");
            Sb.Append(txtCheckDateStart.Text.Trim());
            Sb.Append("'");
        }
        if (txtCheckDateEnd.Text.Trim().Length > 1)
        {
            Sb.Append(" and CI_ValidTime<'");
            Sb.Append(DateTime.Parse(txtCheckDateEnd.Text.Trim()).AddDays(1).ToShortDateString());
            Sb.Append("'");
        }
        int pageCount, rowCount;
        List<Model.CustomerIdentity> properties = new BLL.CustomerIdentity().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "CI_ID", true, Sb.ToString(), out pageCount, out rowCount);
        CustomerIdentityListControl1.Bind(properties);
        AspNetPager1.RecordCount = rowCount;
    }
    #endregion

    #region 分页
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    #endregion
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Check.CheckPermission("200500107", "00010"))
        {
            List<int> s = CustomerIdentityListControl1.Selected;
            if (s.Count > 0)
            {
                StringBuilder sqls=new StringBuilder();
                 bool flag = true;
                foreach (int sql in s)
                {
                    sqls.Append("update customeridentity set CI_Valid=1 ,CI_Validor='");
                    sqls.Append(Share.UserValue(0));
                    sqls.Append("',CI_ValidTime='");
                    sqls.Append(DateTime.Now.ToString());
                    sqls.Append("' where CI_ID=");
                    sqls.Append(sql);
                    if(new BLL.Jet().CountRunSql(sqls.ToString())<1)
                    {
                        flag=false;
                    }
                }
                if (!flag)
                {
                    BLL.Common.Alert(this.Page, "部分记录未审批成功!"); return;
                }
                else
                {
                    BLL.Common.Alert(this.Page, "审批成功!");
                    Bind();
                }
            }
            else
            {
                BLL.Common.Alert(this.Page, "请选择要核准的记录"); return;                
            }
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (Check.CheckPermission("200500107", "00018"))//
        {
            List<int> s = CustomerIdentityListControl1.Selected;
            if (s.Count > 0)
            {
                StringBuilder sqls = new StringBuilder();
                bool flag = true;
                foreach (int sql in s)
                {
                    sqls.Append("update customeridentity set CI_DEL=1 ,CI_DELOP='");
                    sqls.Append(Share.UserValue(0));
                    sqls.Append("',CI_DELTime='");
                    sqls.Append(DateTime.Now.ToString());
                    sqls.Append("' where CI_ID=");
                    sqls.Append(sql);
                    if (new BLL.Jet().CountRunSql(sqls.ToString()) < 1)
                    {
                        flag = false;
                    }
                }
                if (!flag)
                {
                    BLL.Common.Alert(this.Page, "部分记录未操作成功!"); return;
                }
                else
                {
                    BLL.Common.Alert(this.Page, "操作成功!");
                    Bind();
                }
            }
            else
            {
                BLL.Common.Alert(this.Page, "请选择要操作的记录"); return;
            }
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Bind();
    }
}
